package cn.edu.scau.cmi.yewangjiang.client;

import org.springframework.context.ApplicationContext;
import cn.edu.scau.cmi.yewangjiang.hibernate.dao.StudentDAO;
import cn.edu.scau.cmi.yewangjiang.hibernate.dao.TeacherDAO;
import cn.edu.scau.cmi.yewangjiang.spring.util.ApplicationContextUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SpringClient extends Application { 
    private static StudentDAO sdao;
    private static TeacherDAO tdao;

    @Override
    public void start(Stage primaryStage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("../spring/SpringScene.fxml"));
            primaryStage.setTitle("实验七");
            primaryStage.setScene(new Scene(root));
            primaryStage.show();
        } catch (Exception e) { 
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ApplicationContext ac = ApplicationContextUtil.getApplicationContext();      

        cn.edu.scau.cmi.yewangjiang.spring.domain.Student zhangsan = (cn.edu.scau.cmi.yewangjiang.spring.domain.Student) ac
                .getBean("zhangsan");

        System.out.println(zhangsan.getName() + "的导师是" + zhangsan.getTutor().getName());  

        sdao = (StudentDAO) ac.getBean("studentDao"); 
        tdao = (TeacherDAO) ac.getBean("teacherDao");
        launch(args);
    }
} 
